<template>
    <transition name="move">
        <div v-show="isShow" class="food-detail">
            <div class="header">
                <img :src="food.image">
                <div class="back" @click="hide">
                    <i class="icon-arrow_lift"></i>
                </div>
            </div>
            <div class="content">
                <div class="title">{{food.name}}</div>
                <div class="info">
                    <span>月售{{food.sellCount}}份</span>
                    <span class="good-rating">好评率{{food.rating}}%</span>
                </div>
                <div class="price">
                    <span class="now">￥{{food.price}}</span>
                    <span v-show="food.oldPrice" class="old">￥{{food.oldPrice}}</span>
                </div>
                <div class="buy-cart">
                    <div class="cart" @click.stop.prevent="addAction">加入购物车</div>
                </div>
            </div>
            <div class="info"></div>
            <div class="rating"></div>
        </div>
    </transition>
</template>

<script>
import { eventBus } from '../../common/event-bus.js'
export default {
    props: {
        food: {
            type: Object
        }
    },
    data() {
        return {
            isShow: false
        }
    },
    methods: {
        hide() {
            this.isShow = false
        },
        show() {
            this.isShow = true
        },
        addAction(event) {
            if (!event._constructed) {
                return
            }
            eventBus.$emit('addCart', event.target)
        }
    }
}
</script>

<style lang="less">
.food-detail {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 46px;
    z-index: 58;
    background: white;
    &.move-enter-active,
    &.move-leave-active {
        transition: all 0.25s ease;
    }
    &.move-enter,
    &.move-leave-to {
        transform: translate3d(100%, 0, 0);
    }
    .header {
        position: relative;
        width: 100%;
        height: 0;
        padding-top: 100%;
        img {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
        .back {
            position: absolute;
            top: 0;
            left: 0;
            margin-top: 20px;
            .icon-arrow_lift {
                font-size: 20px;
                padding-left: 10px;
            }
        }
    }
    .content {
        display: inline-block;
        position: relative;
        width: 100%;
        font-size: 0;
        .title {
            margin: 18px 18px 0 18px;
            font-size: 16px;
            color: #333333;
            font-weight: bold;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .info {
            margin: 10px 18px 18px 18px;
            color: #999999;
            span {
                font-size: 12px;
            }
            .good-rating {
                margin-left: 10px;
            }
        }
        .price {
            margin: 10px 18px 15px 18px;
            .now {
                font-size: 15px;
                font-weight: bold;
                color: rgb(240, 20, 20);
            }
            .old {
                font-size: 13px;
                font-weight: bold;
                color: rgb(147, 153, 159);
                text-decoration: line-through;
            }
        }
        .buy-cart {
            display: inline-block;
            position: absolute;
            bottom: 18px;
            right: 18px;
            .cart {
                font-size: 10px;
                height: 24px;
                line-height: 24px;
                color: #fff;
                background: rgb(0, 160, 220);
                padding: 0 10px;
                border-radius: 12px;
            }
        }
    }
}
</style>
